﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Snowflake.Entity;
using System.Data.Common;

namespace Snowflake.Gateway
{
    /// <summary>
    /// Base class logic for all EntityQueries
    /// </summary>
    /// <typeparam name="TEntity"></typeparam>
    public abstract class EntityQuery<TEntity> where TEntity : EntityObject<TEntity>, new()
    {
        private IQueryable<TEntity> _SelectQuery;

        /// <summary>
        /// Default intialization
        /// </summary>
        protected EntityQuery() { }

        internal IQueryable<TEntity> SelectQuery
        {
            get { return this._SelectQuery; }
        }

        /// <summary>
        /// The constructor that initalize the query from Linq Query
        /// </summary>
        /// <param name="query">The Linq query that initialize</param>
        protected EntityQuery(IQueryable<TEntity> query)
        {
            this._SelectQuery = query;
        }

        /// <summary>
        /// Method that translates the query to T-SQL Script
        /// </summary>
        /// <param name="tableName">The name of the table in the database</param>
        /// <param name="commandText">Current T-SQL of the Linq Query</param>
        /// <param name="parameters">Parameters of the T-SQL of the Linq Query</param>
        /// <returns>Converted T-SQL Query</returns>
        protected internal abstract string TranslateSQLQuery(string tableName, string commandText, DbParameterCollection parameters);
    }
}
